#include "SymbolResolutionDialog.h"
#include "ui_SymbolResolutionDialog.h"

#include <QtCore>

SymbolResolutionDialog::SymbolResolutionDialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::SymbolResolutionDialog)
{
    m_ui->setupUi(this);
    
    connect(m_ui->addressLineEdit, SIGNAL(textEdited(QString)), this, SLOT(resolveAddress(QString)));
    connect(m_ui->symbolLineEdit, SIGNAL(textEdited(QString)), this, SLOT(resolveSymbol(QString)));
}

SymbolResolutionDialog::~SymbolResolutionDialog()
{
    delete m_ui;
}

void SymbolResolutionDialog::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void SymbolResolutionDialog::resolveAddress(const QString& text)
{
    bool parseOk = false;
    unsigned long address = text.toULong(&parseOk, 10);
    if (parseOk) {
        m_ui->symbolLineEdit->setText((*reader)[address]);
    }
}

void SymbolResolutionDialog::resolveSymbol(const QString& text)
{
    if (text.size() > 0) {
        unsigned long address = reader->address(text);
        m_ui->addressLineEdit->setText(QString("%1").arg(address));
    }
    else {
        m_ui->addressLineEdit->setText("");
    }
}
